#ifndef MYSINGLETON_H
#define MYSINGLETON_H

#include <iostream>

template <class T>
class MySingleton
{
public:
    MySingleton()
    {

    }

    ~MySingleton()
    {
        if(sh) delete sh;
    }

    T* get()
    {
        //static std::once_flag _oc;
        std::call_once(_oc, []{sh = new T;});
        return sh;
    }

private:
    static std::once_flag _oc;
    static T* sh;
};

template <class T> T* MySingleton<T>::sh = nullptr;
template <class T> std::once_flag MySingleton<T>::_oc;

#endif // MYSINGLETON_H
